package io.github.harmonly.skyblock;

import dev.jorel.commandapi.CommandAPI;
import dev.jorel.commandapi.CommandAPIBukkitConfig;
import io.github.harmonly.skyblock.game.pets.PetDataManager;
import io.github.harmonly.skyblock.manager.*;
import io.github.harmonly.skyblock.util.Scheduler;
import org.bukkit.plugin.java.JavaPlugin;

public final class SkyBlock extends JavaPlugin {

    private static SkyBlock plugin;

    public static SkyBlock getInstance() {
        return plugin;
    }

    public static String lang() {
        return ResourcesManager.getConfig("config").get("lang", "en_us").toString();
    }

    @Override
    public void onLoad() {
        plugin = this;
        CommandAPIBukkitConfig commandAPIBukkitConfig = new CommandAPIBukkitConfig(this);
        CommandAPI.onLoad(commandAPIBukkitConfig);
    }

    @Override
    public void onEnable() {
        // 插件启动逻辑
        // 启动CommandAPI
        CommandAPI.onEnable();

        // Scheduler enable
        Scheduler.enable(plugin);

        // 配置数据管理器器
        ResourcesManager.setup(plugin);
        DataManager.enable();

        // 注册命令
        CommandManager.registerCommands();

        // 注册事件监听器
        ListenerManager.registerListeners();

        PetDataManager.init();
    }

    @Override
    public void onDisable() {
        // 插件关闭逻辑
        DataManager.disable();
        ResourcesManager.saveConfig("config");
        WorldManager.disable();
        // 关闭CommandAPI
        CommandAPI.onDisable();
    }
}
